<?php
/**
 * 查询year是2013年的所有电影
 * author: JiangJun
 * CreateTime:2021/7/25 21:51
 */


require '../vendor/autoload.php';


use Aws\DynamoDb\Exception\DynamoDbException;
use Aws\DynamoDb\Marshaler;

$sdk = new Aws\Sdk([
    'region'   => 'us-west-2',
    'version'  => 'latest',
    'credentials' => [
        'key' => 'AKIA4SBKFCJAXUOUXUN2',
        'secret' => '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',
    ],
]);

$dynamodb = $sdk->createDynamoDb();
$marshaler = new Marshaler();

$tableName = 'live';

$params = [
    'RequestItems'=>[
        $tableName =>[
            'Keys' => [
                //查询多条数据，作为一次请求来发送
                $marshaler->marshalItem(['channel_id'=>'618ce82659f1a']),
                $marshaler->marshalItem(['channel_id'=>'618ce82b43466']),
                $marshaler->marshalItem(['channel_id'=>'618ce82bb2fc8']),
                $marshaler->marshalItem(['channel_id'=>'618ce810d7dcf']),
                $marshaler->marshalItem(['channel_id'=>'618ce8310efb3']),
            ],
        ],

    ],
];


try {
    $result = $dynamodb->batchGetItem($params);
    foreach ($result['Responses'][$tableName] as $v) {
        print_r($marshaler->unmarshalItem($v));
    }

} catch (DynamoDbException $e) {
    echo "Unable to batch get item:\n";
    echo $e->getMessage() . "\n";
}